package com.linkallcloud.deapi;

import java.io.Serializable;

import org.apache.commons.beanutils.BeanUtils;

import com.alibaba.fastjson2.annotation.JSONField;


public class DeResponse implements Serializable {
    private static final long serialVersionUID = -7799289782544283034L;

    private String id;// 消息ID（发送方提供）
    private String tid;// 消息ID（de生成）

    private String code;// 错误码
    private String message;// 错误信息

    private String content;// 响应消息内容

    private Long dt;// 消息时间

    public DeResponse() {
        super();
    }

    public DeResponse(DeRequest req, String content) {
        this(req.getId(), req.getTid(), "0", "success");
        this.content = content;
    }

    public DeResponse(DeRequest req, String code, String message) {
        this(req.getId(), req.getTid(), code, message);
    }

    public DeResponse(String id, String tid, String content) {
        this(id, tid, "0", "success");
        this.content = content;
    }

    public DeResponse(String id, String tid, String code, String message) {
        super();
        this.id = id;
        this.tid = tid;
        this.code = code;
        this.message = message;
        this.dt = System.currentTimeMillis();
    }

    public static DeResponse example(DeRequest req) {
        return new DeResponse(req, "example_response_content");
    }

    public DeResponse clone() {
        DeResponse dr = new DeResponse();
        try {
            BeanUtils.copyProperties(dr, this);
        } catch (Throwable e) {
            // log.warn("Fail to copy properties!", e);
        }
        return dr;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTid() {
        return tid;
    }

    public void setTid(String tid) {
        this.tid = tid;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Long getDt() {
        return dt;
    }

    public void setDt(Long dt) {
        this.dt = dt;
    }

    @JSONField(serialize = false)
    public boolean isSuccess() {
        return "0".equals(this.getCode());
    }

}
